<?php

namespace App\Kuafu\Log\Model;

use App\Kuafu\Base\Model\BaseModel;
use App\Kuafu\Base\Model\Traits\KfSoftDeletes;
use App\Kuafu\Base\Model\Traits\KfUid;
use App\Kuafu\Shop\Enum\ShopCodeEnum;
use App\Kuafu\Shop\Exceptions\ShopException;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class UserLoginLogModel extends BaseModel
{
    use HasFactory;

    protected $table = 'user_login_logs';

    protected $fillable = ['userId', 'userName', 'mobile', 'ip', 'longitude', 'latitude', 'serialNumber', 'type'];

    protected $appends = ['ipReal'];

    //日志记录数量
    const USER_LOGIN_LOG_COUNT = 1; //为1时是首次登录

    //以5s为登陆时间的间值
    const LOGIN_FIRST_TIME = 5;

    //用户是否为第一次登录
    const USER_LOGIN_FIRST_YSE = 1;  //是
    const USER_LOGIN_FIRST_NO  = 0;  //否

    public function getIpRealAttribute(): string
    {
        return $this->ip ? long2ip($this->ip) : '';
    }
}
